// 章表

const { STRING, INTEGER, DATE } = require("sequelize");

const sequelize = require("../sequelize");

const Chapter = sequelize.define("Chapter",{
    title:{
        type:STRING(50),
        allowNull:false,
        unique:true,
        comment:"章名称"
    },
    createdate:{
        type:DATE,
        comment:"创建时间"
    },
    update:{
        type:DATE,
        comment:"修改时间"
    },
    creadator:{
        type:DATE,
        comment:"修改者"
    },
    updator:{
        type:DATE,
        comment:"修改者"
    },
    catalogueid:{
        type:INTEGER(36),
        allowNull:false,
        comment:"对应目录ID 唯一值"
    }
})

Chapter.associate = function(){
    Chapter.belongsTo(sequelize.catalogue,{
        foreignKey:"catalogueid",
        target:"id"
    })
    Chapter.hasMany(sequelize.Section,{
        foreignKey:"chapterid",
        target:"id"
    })
}

module.exports = Chapter